package com.jing.cloud.service.group.method;

import com.jing.cloud.service.group.bean.Group;
import com.jing.cloud.service.group.constant.GroupErrCode;
import com.jing.cloud.service.group.helper.GroupHelper;
import com.jing.cloud.service.group.method.param.MemberBean;
import com.jing.cloud.service.method.AbstractMethod;
import com.jing.cloud.service.method.Method;
import com.jing.cloud.service.Res;
import com.jing.cloud.util.RspUtil;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by 29017 on 2017/9/20.
 */
public class RemoveMembers extends AbstractMethod<MemberBean> implements Method<MemberBean> {

    @Autowired
    private GroupHelper groupHelper;

    @Override
    public Res call(MemberBean memberBean) throws Exception {
        Group group = groupHelper.getGroup(memberBean.getGroupId());
        if (null == group) {
            return RspUtil.error(GroupErrCode.GROUP_NOT_EXIST);
        }
        return groupHelper.removeMembers(memberBean.getGroupId(), memberBean.getUserIds());
    }
}
